#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class min_heap
{
private:
    vector<int> heap;
public:
    min_heap()=default;
    int input(int n);
    void output();
    bool isEmpty(){return heap.empty();}
};

int main()
{
    min_heap* h=new min_heap();
    int n=0,temp=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        h->input(temp);
    }
    h->output();
    return 0;
}


int min_heap::input(int n)
{
    heap.push_back(n);
    int p=heap.size();
    while(p!=1)
    {
        if(heap[p-1]<heap[p/2-1])
            swap(heap[p-1],heap[p/2-1]);
        p/=2;
    }
    return 0;
}

void min_heap::output()
{
    vector<int>::iterator iter=heap.begin();
    for_each(heap.begin(),heap.end(),[&](int n){cout<<n;if(!(++iter==heap.end())) cout<<" ";});
}
